#email id
#course id
#assignment id
#type_of_prob = no_attachment, not_pdf, corrupt_pdf

from fetchemApp.models import *
import smtplib

def pdfchk(stud_object, course_object, assign_object, type_of_prob):
    smtpserver = smtplib.SMTP("smtp.gmail.com",587)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    
    user = course_object.SubEmail
    pswd = course_object.SubPassword
    try:
        smtpserver.login(user, pswd)
    except:
        return 'Unable to Login'
    
    to = stud_object.Email
    sub = '['+course_object.CourseNo+'] '+assign_object.SubjectLine+ '- Submission Response'
    body = 'Dear '+stud_object.Name+'\n\n'+'Your submission for '+assign_object.SubjectLine+', '+course_object.CourseNo+' '

    if type_of_prob == 'no_attachment':
        body = body + 'had no attachment.'
    if type_of_prob == 'not_pdf':
        body = body + 'did not contain a PDF file.'
    if type_of_prob == 'corrupt_pdf':
        body = body + 'had a corrupt PDF file.'
        
    body = body + '\n Kindly submit again with a valid PDF file.'+'\n\nCheers\nTeam Fetch''em'
    header = 'To:' + to + '\n' + 'From: ' + user + '\n' + 'Subject:' + sub + '\n'
    msg = header + '\n' + body
    smtpserver.sendmail(user, to, msg)
    print 'Mail Sent!'
    smtpserver.close()